/*
 *  BitmapImage.h
 *  MondialiSciAlpinismo
 *
 *  Created by Giorgio Tino on 2/11/13.
 *  Copyright 2013 __MyCompanyName__. All rights reserved.
 *
 */

#if !defined(BitmapImage_H)
#define BitmapImage_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Bitmap.h"

#include <plib/ssg.h>

typedef enum {
	eAlphaKey_NONE,
	eAlphaKey_RED,
	eAlphaKey_GREEN,
	eAlphaKey_BLUE
}eAlphaKey;

class ssgTexture;

class BitmapImage  
{
	public:
		BitmapImage();
		BitmapImage(const char *filename, const eAlphaKey alphaKey = eAlphaKey_NONE, const float x = 0.0f, const float y = 0.0f, const float dx = 1.0f, const float dy = 1.0f);
		virtual ~BitmapImage();
	
		virtual void display();
		virtual bool hitTest(int b, int s, int x, int y);

	protected:
		bool hidden;
		float texCoordX;
		float texCoordY;
		float x;
		float y;
		float dx;
		float dy;
	
		ssgTexture* texture;
		
		virtual void update(){};
	
		inline int pow2roundup(int x)
		{
			if (x < 0)
				return 0;
			--x;
			x |= x >> 1;
			x |= x >> 2;
			x |= x >> 4;
			x |= x >> 8;
			x |= x >> 16;
			return x+1;
		}

	private:
		char             *fileName;    /* Bitmap file name */
		
		int h,w;                       // image size in pixels
		int bh,bw;                     // texture size (pow of 2) in pixels
	
		GLuint texId;
	    eAlphaKey alphaKey;
		
		int createTexture();
};

#endif